
import 'package:find_friend/common/alert_tool.dart';
import 'package:find_friend/common/common_widget.dart';
import 'package:find_friend/const/const.dart';
import 'package:find_friend/network/network.dart';
import 'package:find_friend/pages/mine/model/followmodel.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

import '../mine_follow.dart' show MineFollowCell,SelectAllfootWidget;

class SettingBlacklistPage extends StatefulWidget {

  @override
  _SettingBlacklistPageState createState() => _SettingBlacklistPageState();
}

class _SettingBlacklistPageState extends State<SettingBlacklistPage> {
  
  bool selectall = false;
  bool offstage = false;
  List<FollowModel> list = [];

  @override
  void initState() {
    super.initState();

    _requestBlackList();
  }

  void _requestBlackList() {
    Networktool.request(API.friend, params: {"gid": -1,}, method: NETWORKHTTPMethod.GET, success: (data){
      if(data != null) {
        List arr = data["data"];
        if(arr != null) {
          arr.forEach((element) { 
            list.add(FollowModel.fromJson(element));
          });
        }
        if(mounted) setState(() {});
      }
    });
  }

  void _moveToFriend(FollowModel model) {
    Networktool.request(API.friendgroupset, params: {"gid": 0, "mobile":model.mobile}, method: NETWORKHTTPMethod.POST, success: (data){
      if(data != null) {
        setState(() {
          list.remove(model);
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("黑名单"),
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: IconButton(
          onPressed: (){
            Navigator.of(context).pop();
          },
          icon: Image.asset("assets/fanhui.png"),
        ),
        actions: [
          // IconButton(
          //   icon: Image.asset("assets/sousuo.png"),
          //   onPressed: (){},
          // ),
          // IconButton(
          //   icon: Image.asset("assets/bianji.png"),
          //   onPressed: (){
          //     selectall = false;
          //     setState(() {
          //       offstage = !offstage;
          //     });
          //   },
          // ),
        ],
      ),
      body: SafeArea(
        bottom: offstage,
        child: Column(
          children: [
            Expanded(
              child: ListView.builder(
                itemCount: list.length,
                itemBuilder: (context, index){
                  final model = list[index];
                return Slidable(
                  actionPane: SlidableDrawerActionPane(),
                  actionExtentRatio: 0.18,// 按钮所占的宽度
                  secondaryActions: [
                    SlideAction(
                      color: APP_verify_error_color,
                      onTap: (){
                        AlertTool.showConfirmDialog(context, title: "提示\n确定取消[${model.username}]的黑名单", sureCallback: () => _moveToFriend(list[index]));
                      },
                      child: Text("取消黑名单",style: instanceTextStyle(11, Colors.white),),
                    ),
                  ],
                  child: Container(
                      padding: const EdgeInsets.only(left: 20, top: 11.5, right: 0),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              CustomCircleAvatar(size: 46.h,url: model?.avatar,),
                              SizedBox(width: 10,),
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(model?.username ?? "", style: instanceTextStyle(14, APP_font_black),),
                                    Container(
                                      child: Text(
                                        "${model?.bio ?? ''}",
                                        maxLines: 2,
                                        overflow: TextOverflow.ellipsis,
                                        style: instanceTextStyle(10, APP_font_black),
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                          SizedBox(height: 9,),
                        ],
                      ),
                    ),
                );
              }),
            ),
            // SelectAllfootWidget(isselect: selectall,offstage: !offstage,onTap: (){
            //   setState(() {
            //     selectall = !selectall;
            //   });
            // },)
          ],
        ),
      ),
    );
  }
}